package com.tyijian.admin.redis.listener;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;

import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;

/**
 * redis 订阅功能，这里主要是监听登录
 * 
 * @author yangjp
 *
 */
public class UserLoginRedisListener implements MessageListener {
	
	private static final Logger logger = LoggerFactory.getLogger(UserLoginRedisListener.class);

	@Override
	public void onMessage(Message message, byte[] pattern) {
		if (message != null && ArrayUtils.isNotEmpty(message.getBody())) {
			ByteArrayInputStream bis = new ByteArrayInputStream(message.getBody());
			try {
				ObjectInputStream ois = new ObjectInputStream(bis);
				logger.info("用户："+ois.readObject()+" 登录了系统");
			} catch (Exception e) {
				logger.error(e.getMessage());
			}
		}
	}

}
